<?php

class Confirm_gas_fee extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Confirm_gas_fee':
	 * @var integer $id
	 * @var integer $fk_confirm_id
	 * @var double $unit_price
	 * @var double $amount
	 * @var double $cost
	 * @var integer $state
	 * @var string $create_time
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'confirm_gas_fee';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			//array('fk_confirm_id, state', 'numerical', 'integerOnly'=>true),
			array('unit_price, amount, cost', 'numerical'),
			array('unit_price,amount,cost', 'required'),
			array('amount', 'match','pattern' => '/^\d{1,8}(\.\d{1,2})?$/','message'=>'{attribute} 整数位最多8位，小数位2位'),
			array('unit_price,cost', 'match','pattern' => '/^\d{1,16}(\.\d{1,2})?$/','message'=>'{attribute} 整数位最多16位，小数位2位'),
		);
	}

	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)
	{
		if($this->isNewRecord){
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
		}
		return true;
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '索引号',
			'fk_confirm_id' => '确认单Id',
			'unit_price' => '燃油单价',
			'amount' => '油量',
			'cost' => '油费',
			'state' => '状态',
			'create_time' => '创建时间',
		);
	}
}